import { defineConfig,loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
// import path from 'path'
import { resolve  } from 'path';
// https://vite.dev/config/
export default({ mode }) => defineConfig({
  server:{
    port : 9999,
    open : true,
    cors : true,
    proxy: {
          '/api': { // 匹配请求路径，localhost:3000/snow
          target: loadEnv(mode, process.cwd()).VITE_BASE_API, // 代理的目标地址
          changeOrigin: true, // 开发模式，默认的origin是真实的 origin:localhost:3000 代理服务会把origin修改为目标地址
          // secure: true, // 是否https接口
          ws: false, // 是否代理websockets
          // rewrite target目标地址 + '/abc'，如果接口是这样的，那么不用重写
          rewrite: (path) => path.replace(/^\/api/, '') // 路径重写，本项目不需要重写
      }
    },
  },
    resolve: {
       alias: {
        '@': resolve(__dirname, './src'),
      },
    },
  plugins: [vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
})
